<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title>采购计划汇总</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>采购计划汇总</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#">采购计划汇总</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
            <div class="input">
            	<div class="textalign1">项目名称：</div>
            	<div class="boxinput">
            		<input class="textinput" type="text" id="name" name="name" placeholder="项目名称" />
            	</div>
            	<div class="textalign">项目状态：</div>
            	<div class="boxinput">
            		<select class="textinput"  id="status" name="status">
                        	<option value="">请选择</option>
                        	<option value="1">启用</option>
                        	<option value="0">停用</option>
                        </select>
            	</div>
            	<div class="textalign">
            		<button type="button" onclick="gridSerch()" class="btn btn-success btn-sm" id="selectc">查&nbsp;询</button>
            	</div>
            </div>
            </div>
        </div>

        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>

    </section>
    <form action="${ctx}/bidProjCompany/toList.html" method="post" id="Form">
    <input type="hidden" name="projId" id="projId">
    <input type="hidden" name="newname" id="newname">
    </form>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
    
    //绑定回车
    $('#name,#status').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectc').click();
        }
    }); 
		
    $("#name").focus();//加载页面光标在第一个查询框内
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "${pageContext.request.contextPath}/bidProject/getProjWithPlanList.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                //shrinkToFit: false,
                height: 255,
                colNames: ['操作','projId','项目编号','项目名称', '项目类型', '创建时间', '申报开始日期', '申报结束日期', '项目状态'],
                colModel: [
                    { name: 'operate', width: 290, align: 'center' ,sortable: false,
	                  formatter: function (val, opts, rowdata) {
		              var str ="";
		              str += "<a href='javascript:proByDrug(\"" + rowdata.projId + "\"" + ",\"" + rowdata.projName + "\"" +")' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -40px -60px' class='opIcon' title='按药品汇总'></a>";
	                	str += "<a href='javascript:proByHosp(\"" + rowdata.projId + "\"" + ",\"" + rowdata.projName + "\"" +")' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -160px 0px' class='opIcon' title='按医疗机构汇总'></a>";
	                	str += "<a href='javascript:proByArea(\"" + rowdata.projId + "\"" + ",\"" + rowdata.projName + "\"" +")' >按地区汇总</a>";
		              return str;
	                   }	
                    },
                    { name: 'projId',hidden:true, key:true,width: 40, align: 'center' ,sortable: false},
                    { name: 'projCode', width: 88, align: 'center' ,sortable: false},
                    { name: 'projName', width: 280, align: 'center' ,sortable: false},
                    { name: 'projCat', width: 88, align: 'center' ,sortable: false},
                    { name: 'createDatatime',hidden:true, width: 80, align: 'center' ,sortable: false},
                    { name: 'starttime', width: 104, align: 'center' ,sortable: false},
                    { name: 'endtime', width: 120, align: 'center' ,sortable: false},
                    { name: 'status', width: 90, align: 'center' ,sortable: false,
                    	formatter:function (val,opts,rowdata){
                    		if(rowdata.status == 1){
                    			return "启用";
                    		}else if(rowdata.status == 0){
                    			return "停用";
                    		}else{
                    			return "";
                    		}
                    	}
                    }
                    
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
                caption: "采购项目列表",
                jsonReader: {
                    repeatitems: false  
                },
                loadComplete: function (data) {
                    formatSelect("#projId",data.rows);
                },
                gridComplete:function(){
                    //序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                }

            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        function gridSerch() {
        	var name = $("#name").val();
        	var status = $("#status").val();
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"name":name,
    	        		"status":status}
    	    }).trigger("reloadGrid"); //重新载入  
    	}
        function toAddhosp(projId,name){
        	window.location.href=encodeURI("${ctx}/bidProject/toHospList.html?projId="+projId+"&proName="+name);
        }
        function getForm(projId,name){
        	$("#projId").val(projId);
        	$("#newname").val(name);
        	$("#Form").submit();
        }
        function switchStatus(id, status) {
        	var msg = "";
        	if (status == 1){
        		msg = "启用";
        	} else if (status == 0){
        		msg = "停用";
        	}
        	 $.HN.message.confirm('确定'+msg+'吗？', '', '').on(function (e) {
        		 if(e){
        			 $.post("${pageContext.request.contextPath}/bidProject/switchStatus.html", {
        				 projId : id,
        				 status : status
        	    		}, function(result) {
        	    			
        	    			if (result == "success") {
        	    				gridSerch();
        	    				$.HN.message.alert("操作成功！", "消息", "success");
        	    			} else {
        	    				$.HN.message.alert("操作失败！", "消息", "error");
        	    			}
        	    		}, "json");
        		 }
        		 
        	 });
    	}
        function proByDrug(projId, projName) {
        	window.location.href = encodeURI(encodeURI("${ctx}/bidHospplan/toProjByDrugList.html?projId=" + projId + "&projName=" + projName));
        }
        function proByHosp(projId, projName) {
            window.location.href = encodeURI(encodeURI("${ctx}/bidHospplan/toBidCollectByHospList.html?projId=" + projId + "&projName=" + projName));
        }
        
        function proByArea(projId, projName) {
            window.location.href = encodeURI(encodeURI("${ctx}/bidHospplan/toBidCollectByAreaList.html?projId=" + projId + "&projName=" + projName));
        }
        
    </script>
</body>
</html>
